<script type="text/javascript">
$(document).ready(function(){
	$("#mode").change(function(){
		var mode = $(this).val();
		if(mode=='month'){
			$("#tr_month").show();
			$("#tr_year").hide();
		}
		else if(mode=='year'){
			$("#tr_month").hide();
			$("#tr_year").show();
		}
	})
	
	var count = 0;
	$(".count").each(function(){
		count += parseInt($(this).text());
	});
	$(".rscount").text(count);
})
</script>
<h2>รายงาน 10 อันดับ เรื่องที่มีการดาวน์โหลดมากที่สุด</h2>
<form>
	<div id="advancedSearch">
		<table width="95%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td colspan="2"  class="topic_advancedSearch"><img src="images/topic_advancedSearch2.gif" /></td>
		  </tr>		  	 
		  <tr id="tr_month">
			<td width="180"><br>ปี</td>
			<td>
				<select name="start_year">
					<? 
					$cyear= date("Y");
					for($i=0;$i<10;$i++):
						$year=$cyear-$i;
					?>
					<option value="<?=$year;?>" <?=(@$_GET['start_year'] == $year)?"selected=selected":"";?>><?=$year+543;?></option>
					<? endfor;?>					
				</select>							
			</td>
		  </tr>	
		  	<tr id="tr_month">
			<td width="180"><br>เดือน</td>
			<td>
				<select name="month">
					<? 
					$month = get_month();
					foreach($month as $key=>$item):
					?>
					<option value="<?=$key;?>" <?=(@$_GET['month'] == $key)?"selected=selected":"";?>><?=$item;?></option>
					<? endforeach;?>					
				</select>							
			</td>
		  </tr>	
		  <tr>
			<td width="180"><br>ประเภทข้อมูล</td>
			<td>
				<?=form_dropdown('type_id',get_option('id','title','tbknowledgetype'),@$_GET['type_id'],'','--เลือกทั้งหมด--',0);?>
			</td>
		  </tr>				  
		  <tr>
			<td>&nbsp;</td>
			<td><input type="submit" name="submit" value="ค้นหา" ></td>
		  </tr>
		</table>
	</div>
</form>

<?php if($_GET):?>
<div id="main-content">
	<table class="tbContainer">
		<tr>
			<td>
			
				<table border="0" cellpadding="10" cellspacing="0" width=""  >
						<tr class="ui-state-error">
							<td colspan="3" class="ui-state-error tdlist" style="text-align:center;">ปี <?=$_GET['start_year']+543?></td>
						</tr>
						<tr class="ui-state-error">
							<td class="ui-state-error tdlist" style="width:150px;">ประเภทข้อมูล</td>
							<td class="ui-state-error tdlist" style="width:150px;">เรื่อง</td>
							<td class="ui-state-error tdlist" style="text-align: center;width:250px;">จำนวนการดาวน์โหลด (ครั้ง)</td>							
						</tr>
						<?php foreach($knowledges as $knowledge):?>
						<tr>
							<td class="tdlist" style="width:150px;"><?=$knowledge['kntypetitle']?></td>
							<td class="tdlist"><?=$knowledge['kntitle']?></td>
							<td class="tdlist count" style="text-align: right;padding-right: 20px;"><?=$knowledge['download_count']?></td>
							
						</tr>
						<?php endforeach;?>

						<tr class="ui-state-error">
							<td class="ui-state-error tdlist" style="width:150px;"></td>
							<td class="ui-state-error tdlist" style="width:150px;">รวม</td>
							<td class="ui-state-error tdlist rscount" style="text-align: right;padding-right: 20px;"></td>							
						</tr>
				</table>				
			</td>
		</tr>
	</table>
</div>
<?php endif;?>   